package com.zhu.commons.base;


import com.zhu.commons.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice  //捕捉全局异常
@Component
@Slf4j
/**
 * 全局异常处理
 */
public class GlobalException {

    @ExceptionHandler(value = Exception.class)
    public R handleException(Exception e){
        log.error(e.getMessage(),e);
        return R.error().message(e.getMessage());
    }





    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public R handleException(BusinessException e){
        log.error(e.getMessage(),e);
        return R.error().message(e.getMessage());
    }


}
